<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of quanly_hoidap
 *
 * @author Bui
 */
class Quanly_hoidap extends CI_Controller {

    //put your code here
    public function __construct() {
        parent::__construct();
    }

    private $limit = 10;

    function manage_all_questions($offset = 0) {
//       $this->load->model('hoidap_model');
//       $data['result'] = $this->hoidap_model->load_all_questions();
        // offset

        $uri_segment = 4;
        $offset = $this->uri->segment($uri_segment);

        // load data
        $this->load->model('hoidap_model');
        $data['result'] = $this->hoidap_model->get_paged_list($this->limit, $offset)->result();

        // generate pagination
        $this->load->library('pagination');
        $tuychinh['base_url'] = site_url('/hoidap/quanly_hoidap/manage_all_questions');
        $tuychinh['total_rows'] = $this->hoidap_model->count_all();
        $tuychinh['per_page'] = $this->limit;
        $tuychinh['uri_segment'] = $uri_segment;
        $this->pagination->initialize($tuychinh);
        $data['pagination'] = $this->pagination->create_links();


        // generate table data
        $this->load->library('table');
        $this->table->set_empty("&nbsp;");
        $this->table->set_heading('ID', 'Câu hỏi', 'Xem', 'Xóa');

        foreach ($data['result'] as $row) {
       //     $this->table->add_row($row['id'], $row['tieude'], anchor('hoidap/quanly_hoidap/manage_detail_question/' . $row['id'], 'view', array('class' => 'view')), anchor('/hoidap/quanly_hoidap/delete/' . $row['id'], 'delete', array('class' => 'delete', 'onclick' => "return confirm('Are you sure want to delete this question?')"))
       //     );
             $this->table->add_row($row->id, $row->tieude, anchor('hoidap/quanly_hoidap/manage_detail_question/' . $row->id, 'view', array('class' => 'view')), anchor('/hoidap/quanly_hoidap/delete/' . $row->id, 'delete', array('class' => 'delete', 'onclick' => "return confirm('Are you sure want to delete this question?')"))
            );
            
        }
        $data['table'] = $this->table->generate();


        // load view
        $this->load->view('user/hoidap/manage_list_hoidap', $data);
    }

    function manage_detail_question($id) {
        $this->load->view('user/common/header_view', $data);
        $this->load->view('user/common/left_sidebar_view', $data);
        $this->load->view('user/common/head_content_view', $data);

        $this->load->model('hoidap_model');
        $data['records'] = $this->hoidap_model->load_question($id)->row_array();
        $this->load->view('user/hoidap/manage_detail_hoidap', $data);

        $this->load->view('user/common/right_sidebar_view', $data);
        $this->load->view('user/common/footer_view', $data);
    }

    function delete($id) {
        // delete person
        $this->load->model('hoidap_model');
        $this->hoidap_model->delete_question($id);

        // redirect to person list page
        redirect('/hoidap/quanly_hoidap/manage_all_questions', 'refresh');
    }

}

?>
